package alp.starcode.sanping.dict.service;

import alp.starcode.common.base.exception.ParamsNullException;
import alp.starcode.sanping.dict.vo.DictDataVO;
import alp.starcode.sanping.framework.base.BaseService;
import alp.starcode.sanping.framework.database.mariadb.mybatis.dao.SysDictDataDao;
import alp.starcode.sanping.framework.database.mariadb.mybatis.entity.Information;
import alp.starcode.sanping.framework.database.mariadb.mybatis.entity.SysDictData;
import cn.hutool.core.bean.BeanUtil;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * TODO
 *
 * @author wujie
 * @date 2024/3/21 13:03
 */
@Service
public class DictService extends BaseService {

    @Autowired
    SysDictDataDao sysDictDataDao;

    public List<DictDataVO> getDictDataList(String dictType){
        if (dictType != null && !dictType.isEmpty()) {
            MPJLambdaWrapper<SysDictData> queryWrapper = new MPJLambdaWrapper<>();
            queryWrapper.selectAll(SysDictData.class);
            queryWrapper.eq(SysDictData::getDictType, dictType);
            queryWrapper.orderByAsc(SysDictData::getDictSort);
            //构建排序条件
            return BeanUtil.copyToList(this.sysDictDataDao.list(queryWrapper), DictDataVO.class);
        } else {
            throw new ParamsNullException("dictType参数不能为空！");
        }
    }
}
